package com.lifeng.handler;
import com.lifeng.util.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author: lifeng
 * @description:
 **/
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

	@ExceptionHandler(RuntimeException.class)
	public R handlerRuntimeExceptionException(RuntimeException e){
		log.error("出现了运行时异常,{}",e.getMessage());
		return R.error().code(HttpStatus.FORBIDDEN.value()).message("运行时出错了!");
	}
	@ExceptionHandler(Exception.class)
	public R handlerExceptionException(Exception e){
		log.error("未知异常,{}",e.getMessage());
		return R.error().code(HttpStatus.FORBIDDEN.value()).message("未知异常");
	}
}
